<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/empresarial_dependiente.class.php");
	include("includes/class/payRoll.class.php");
    
	
    $empresarial_dependiente = new Empresarial_dependiente();
    $nomina = new Payroll();
    
    
	$company =  $empresarial_dependiente->companyList();
	$employed = $empresarial_dependiente->empleadoList();
	$parameter = $empresarial_dependiente->parameterList();
	
	$eps_code = $hdv_code  = 0;
		
	$where_employed = "";
	
	$employed3			= '';
	$employed4			= '';
	
	$getNumber = $empresarial_dependiente->getNumberReceipt();
	$getNumber= $getNumber+1;
	$emde_code = 0;
	$emde_receipt = cerosIzquierda($getNumber);	

	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
			
	if(isset($_POST['addNomina']) && $_POST['addNomina'] == 1){
        $countEmp = $_POST["count"];
		$action = $_POST["action"];
		
            $data->pay_date_ini         = cambiarFormatoFecha(trim(mysql_real_escape_string($_POST['desde'])),2);
    		$data->pay_date_end         = cambiarFormatoFecha(trim(mysql_real_escape_string($_POST['hasta'])),2);
    		$data->pay_company          = trim(mysql_real_escape_string($_POST['country']));
        
       $id=$nomina->addPayroll($data);
			
	for ($i=0;$i<$countEmp;$i++)
        {   $nombre='nombre'.$i;
            $cedula='cedula'.$i;
            $basico='basico'.$i;
            $dias='dias'.$i;
            $valor1_='valor1_'.$i;
            $der='der'.$i;
            $aux='aux'.$i;
            $con='con'.$i;
            $total='total'.$i;
            $descu='descu'.$i;
            $AH='AH'.$i;
            $AP='AP'.$i;
            $salud='salud'.$i;
            $pension='pension'.$i;
            $neto='neto'.$i;
        
            
            $dataDetail[$i]->pay_det_pay_id      = $id;
            $dataDetail[$i]->pay_det_name        = trim(mysql_real_escape_string($_POST[$nombre]));
    		$dataDetail[$i]->pay_det_idUser      = trim(mysql_real_escape_string($_POST[$cedula]));
    		$dataDetail[$i]->pay_det_salary      = trim(mysql_real_escape_string($_POST[$basico]));
            $dataDetail[$i]->pay_det_days        = trim(mysql_real_escape_string($_POST[$dias]));
            $dataDetail[$i]->pay_det_value_ign   = trim(mysql_real_escape_string($_POST[$valor1_]));
            $dataDetail[$i]->pay_det_der         = trim(mysql_real_escape_string($_POST[$der]));
            $dataDetail[$i]->pay_det_aux         = trim(mysql_real_escape_string($_POST[$aux]));
            $dataDetail[$i]->pay_det_con         = trim(mysql_real_escape_string($_POST[$con]));
            $dataDetail[$i]->pay_det_discount    = trim(mysql_real_escape_string($_POST[$descu]));
            $dataDetail[$i]->pay_det_ah          = trim(mysql_real_escape_string($_POST[$AH]));
            $dataDetail[$i]->pay_det_ap          = trim(mysql_real_escape_string($_POST[$AP]));
            $dataDetail[$i]->pay_det_salud       = trim(mysql_real_escape_string($_POST[$salud]));
            $dataDetail[$i]->pay_det_pension     = trim(mysql_real_escape_string($_POST[$pension]));
            $dataDetail[$i]->pay_det_neto        = trim(mysql_real_escape_string($_POST[$neto]));
        }
        if($nomina->addPayrollDetail($dataDetail))
        {
            $msg_info = true;
				$_SESSION["msg_cool"] .= 'Se adiciono la Nomina satisfactoriamente..!!!<br />';
			echo "<script> window.location.href='listNomina.php?show_msg=2'</script>";
		}
		else{
			$msg_error = true;
				$_SESSION["msg_cool"] .= 'No pudo ser adicionado el recibo... Sorry..!!!<br />';
			echo "<script> window.location.href='listNomina.php?show_msg=1'</script>";
        }
    }
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;	
		

?>